package com.villaday.idf.adapter2;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.activity.BourbonListActivity;
import com.villaday.idf.activity.MinsuSearchResultActivity;
import com.villaday.idf.activity.SearchMinSu2VActivity;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model.BournSearchhistory;
import com.villaday.idf.model.Search_filtersEntity;
import com.villaday.idf.model2.Find_House_minsu_listEntity;
import com.villaday.idf.model2.MinSuSearch;
import com.villaday.idf.util.PhoneUtil;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.MAllViewsSizeIsShow;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * Created by tudou on 2018/10/8.
 */

public class MinSuSearchHeadAdapter extends AbsRecyclerViewAdapter<MinSuSearch.BodyEntity.GroupsEntity> {


    public MinSuSearchHeadAdapter(Context context) {
        super(context, R.layout.item_minsu_search_head);

    }


    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, final MinSuSearch.BodyEntity.GroupsEntity d, int position) {
        holder.bindTextView(R.id.tv_name, d.getName());
        final TagFlowLayout flSearch = (TagFlowLayout) holder.getView(R.id.fl_search);
        final ImageView imgSearch = (ImageView) holder.getView(R.id.img_search);





        TagAdapter tagAdapter = new TagAdapter(d.getItems()) {
            @Override
            public View getView(FlowLayout parent, int position, Object o) {
                TextView tv = (TextView) LayoutInflater.from(context).inflate(R.layout.tv_minsu,
                        flSearch, false);
                MinSuSearch.BodyEntity.GroupsEntity.ItemsEntity hot = (MinSuSearch.BodyEntity.GroupsEntity.ItemsEntity) o;

                if (hot.getName().length() > 10) {
                    tv.setText(hot.getName().substring(0, 9) + "...");

                } else {
                    tv.setText(hot.getName());

                }
                return tv;
            }
        };
        flSearch.setAdapter(tagAdapter);
        if (imgSearch!=null){
            //两行以下隐藏
            flSearch.setMAllViewsSizeIsShow(new MAllViewsSizeIsShow() {
                @Override
                public void setViewShow(boolean isShow) {
                    if (isShow){
                        imgSearch.setVisibility(View.VISIBLE);
                    }else {
                        imgSearch.setVisibility(View.INVISIBLE);

                    }
                }
            });
        }
        flSearch.specifyLines(2);
        imgSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                imgSearch.setSelected(!imgSearch.isSelected());
                if (imgSearch.isSelected()) {
                    flSearch.specifyLines(9999);
                    flSearch.getAdapter().notifyDataChanged();
                } else {
                    flSearch.specifyLines(2);

                }
            }
        });
        flSearch.setOnTagClickListener(new TagFlowLayout.OnTagClickListener()

        {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {


                //
                Intent intent = new Intent(context, MinsuSearchResultActivity.class);
                intent.putExtra("businessDistrictId", d.getItems().get(position).getId());
                intent.putExtra("area",  d.getItems().get(position).getName());

                context.startActivity(intent);


                return true;
            }
        });
       // setViewHight(flSearch, false);




    }

    private void setViewHight(View view, boolean isMatch) {
        if (isMatch) {
            view.getLayoutParams().height = LinearLayout.MarginLayoutParams.WRAP_CONTENT;
        } else {
            view.getLayoutParams().height = PhoneUtil.dp2px(context, 55);

        }
        view.requestLayout();
    }
}
